package com.ifacebox.software.updater;

import java.io.File;
import java.net.URLEncoder;

/**
 * @author znn
 */
public class SoftwareUpdaterConfig {
    private File fileSoftware;
    private String fileSoftwareDigest;
    private File fileSetupSoftware;
    private String fileSetupSoftwareDigest;
    private File fileUpdaterSoftware;
    private String fileUpdaterSoftwareDigest;
    private String softwareUpdaterAddress;

    public SoftwareUpdaterConfig(String softwareUpdaterAddress, String softwareUpdaterName) {
        this.setFileSoftware(SoftwareUpdaterService.getSoftwareUpdaterFile(softwareUpdaterName));
        this.setFileSetupSoftware(SoftwareUpdaterService.getSoftwareUpdaterFile(String.format("%s.ini", softwareUpdaterName)));
        this.setFileUpdaterSoftware(SoftwareUpdaterService.getSoftwareUpdaterFile(String.format("%s.updater", softwareUpdaterName)));
        try {
            this.setSoftwareUpdaterAddress(String.format("%s/%s", softwareUpdaterAddress, URLEncoder.encode(softwareUpdaterName, "UTF-8")));
        } catch (Exception e) {
            this.setSoftwareUpdaterAddress(String.format("%s/%s", softwareUpdaterAddress, softwareUpdaterName));
        }
    }

    public File getFileSoftware() {
        return fileSoftware;
    }

    public void setFileSoftware(File fileSoftware) {
        this.fileSoftware = fileSoftware;
    }

    public String getFileSoftwareDigest() {
        return fileSoftwareDigest;
    }

    public void setFileSoftwareDigest(String fileSoftwareDigest) {
        this.fileSoftwareDigest = fileSoftwareDigest;
    }

    public File getFileSetupSoftware() {
        return fileSetupSoftware;
    }

    public void setFileSetupSoftware(File fileSetupSoftware) {
        this.fileSetupSoftware = fileSetupSoftware;
    }

    public String getFileSetupSoftwareDigest() {
        return fileSetupSoftwareDigest;
    }

    public void setFileSetupSoftwareDigest(String fileSetupSoftwareDigest) {
        this.fileSetupSoftwareDigest = fileSetupSoftwareDigest;
    }

    public File getFileUpdaterSoftware() {
        return fileUpdaterSoftware;
    }

    public void setFileUpdaterSoftware(File fileUpdaterSoftware) {
        this.fileUpdaterSoftware = fileUpdaterSoftware;
    }

    public String getFileUpdaterSoftwareDigest() {
        return fileUpdaterSoftwareDigest;
    }

    public void setFileUpdaterSoftwareDigest(String fileUpdaterSoftwareDigest) {
        this.fileUpdaterSoftwareDigest = fileUpdaterSoftwareDigest;
    }

    public String getSoftwareUpdaterAddress() {
        return softwareUpdaterAddress;
    }

    public void setSoftwareUpdaterAddress(String softwareUpdaterAddress) {
        this.softwareUpdaterAddress = softwareUpdaterAddress;
    }

    @Override
    public String toString() {
        return "SoftwareUpdaterConfig{" +
                "fileSoftware:" + fileSoftware + "," +
                "fileSoftwareDigest:" + fileSoftwareDigest + "," +
                "fileSetupSoftware:" + fileSetupSoftware + "," +
                "fileSetupSoftwareDigest:" + fileSetupSoftwareDigest + "," +
                "fileUpdaterSoftware:" + fileUpdaterSoftware + "," +
                "fileUpdaterSoftwareDigest:" + fileUpdaterSoftwareDigest + "," +
                "softwareUpdaterAddress:" + softwareUpdaterAddress + "}";
    }
}
